<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php学习笔记[051]</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="show"><span>051 php+mysql会员系统开发（上）</span></div>
<?php include 'include/top.php';?>
<div class="text">
<b>会员系统</b>
file/s051_1.php代码：
<div class="code">
  &lt;?php<br />
    session_start();<br />
    include '../include/conn.php';<br />
    define('VAL','study');//定义常量<br />
    ?&gt;<br />
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;<br />
    &lt;?php<br />
    if(isset($_SESSION['sid'])&amp;&amp;isset($_SESSION['id'])&amp;&amp;isset($_SESSION['jc'])){	//先判断是否有登录操作<br />
    function jctime($time)//建立一个权限时间函数<br />
    {<br />
    $newtime=mktime();<br />
    if($newtime-$time&lt;100)//无操作超过100秒则销毁权限，不到100秒则刷新权限时间<br />
    {<br />
    //echo $newtime-$time;<br />
    $_SESSION['time']=mktime(); <br />
    }<br />
    else<br />
    {<br />
    echo '你登录权限过期请重新登录&lt;a href=&quot;../study051.php&quot;&gt;返回&lt;/a&gt;';<br />
    session_destroy();<br />
    exit();<br />
    }<br />
    }
  $sql=&quot;select * from `study051` where `id`='$_SESSION[id]'&quot;;<br />
    $query=mysql_query($sql);<br />
    $arr=mysql_fetch_array($query);<br />
    jctime($_SESSION['time']);
  if($_SESSION['sid']&gt;1 || $_SESSION['jc'] != md5($arr['uid'].$arr['pw'].VAL))<br />
    {<br />
    echo '你没有权限查看此内容！&lt;br /&gt;';<br />
    exit();<br />
    }<br />
    }<br />
    else	//没有登录过则报警并删除权限退出<br />
    {<br />
    echo '你还没有登录请登陆后再查看该页面！&lt;br /&gt;';<br />
    session_destroy();<br />
    exit();<br />
    }<br />
    ?&gt;<br />
    权限内容1
</div>
本页代码：
<div class="code">
&lt;?php<br />
include_once('include/conn.php');<br />
define('VAL','study');<br />
function jctime($time)//建立一个权限时间函数<br />
{<br />
$newtime=mktime();<br />
if($newtime-$time&lt;100)//无操作超过100秒则销毁权限，不到100秒则刷新权限时间<br />
{<br />
//echo $newtime-$time;<br />
$_SESSION['time']=mktime(); <br />
}<br />
else<br />
{<br />
echo '你登录权限过期请重新登录&lt;a href=&quot;../study051.php&quot;&gt;返回&lt;/a&gt;';<br />
session_destroy();<br />
exit();<br />
}<br />
}<br />
if(isset($_POST['submit']))<br />
{<br />
$sql=&quot;select * from `study051` where `uid`='$_POST[uid]'&quot;;<br />
$query=mysql_query($sql);<br />
$arr=mysql_fetch_array($query);<br />
if(is_array($arr))<br />
{<br />
if($arr['pw']==md5($_POST['pw'].VAL))<br />
{<br />
echo '登录成功&lt;br /&gt;';<br />
$_SESSION['id']=$arr['id'];<br />
$_SESSION['sid']=$arr['sid'];<br />
$_SESSION['jc']=md5($arr['uid'].$arr['pw'].VAL);<br />
$_SESSION['time']=mktime();<br />
jctime($_SESSION['time']);<br />
}<br />
else<br />
{<br />
echo'-_-！您输入的密码有误，请检查后重新登录！&lt;br /&gt;'; <br />
session_destroy();<br />
}<br />
}<br />
else<br />
{<br />
echo &quot;无此用户名$_POST[uid]请检查大小写或误输入&lt;br /&gt;&quot;; <br />
session_destroy();<br />
} <br />
}<br />
?&gt;<br />
&lt;form name=&quot;logon&quot; method=&quot;post&quot; action=&quot;study051.php&quot;&gt;<br />
&lt;input name=&quot;uid&quot;&gt;<br />
&lt;input name=&quot;pw&quot; type=&quot;password&quot;&gt;<br />
&lt;input name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;登录&quot;&gt;&lt;a href=&quot;file/s051_1.php&quot;&gt;查看权限页面&lt;/a&gt;<br />
&lt;/form&gt;<br />
</div>
测试效果
<div class="effect">
<?php
include_once('include/conn.php');
define('VAL','study');
function jctime($time)//建立一个权限时间函数
	{
	$newtime=mktime();
	if($newtime-$time<100)//无操作超过100秒则销毁权限，不到100秒则刷新权限时间
		{
		//echo $newtime-$time;
		$_SESSION['time']=mktime();	
		}
	else
		{
		echo '你登录权限过期请重新登录<a href="../study051.php">返回</a>';
		session_destroy();
		exit();
		}
	}
if(isset($_POST['submit']))
{
$sql="select * from `study051` where `uid`='$_POST[uid]'";
$query=mysql_query($sql);
$arr=mysql_fetch_array($query);
if(is_array($arr))
	{
	if($arr['pw']==md5($_POST['pw'].VAL))
		{
		echo '登录成功<br />';
		$_SESSION['id']=$arr['id'];
		$_SESSION['sid']=$arr['sid'];
		$_SESSION['jc']=md5($arr['uid'].$arr['pw'].VAL);
		$_SESSION['time']=mktime();
		jctime($_SESSION['time']);
		}
	else
		{
		echo'-_-！您输入的密码有误，请检查后重新登录！<br />';	
		session_destroy();
		}
	}
else
	{
	echo "无此用户名$_POST[uid]请检查大小写或误输入<br />";	
	session_destroy();
	}	
}
?>
<form name="logon" method="post" action="study051.php">
<input name="uid">
<input name="pw" type="password">
<input name="submit" type="submit" value="登录"><a href="file/s051_1.php">查看权限页面</a>
</form>
</div>
</div>



</body>
</html>
